# open函数打开一个文件，没有文件会新建，但是路径不对会报错
# 指定文件名，方法（读，写，追加），编码格式
output = open("homework2.txt", "w", encoding="utf-8")
content = ">>> \"鸽子\".encode(\"unicode_escape\").decode()\n" \
          "'\\\\u9e3d\\\\u5b50'\n" \
          ">>> '\\u9e3d\\u5b50'\n" \
          "'鸽子'\n" \
          ">>> len('\\u9e3d\\u5b50')\n" \
          "2\n" \
          "\n" \
          ">>> \"鸽子\".encode(\"utf-8\")\n" \
          "b'\\xe9\\xb8\\xbd\\xe5\\xad\\x90'\n" \
          ">>> b = b'\\xe9\\xb8\\xbd\\xe5\\xad\\x90'\n" \
          ">>> b.decode(\"utf\")\n" \
          "'鸽子'\n" \
          "\n" \
          ">>> import chardet\n" \
          ">>> chardet.detect(b)\n" \
          "{'encoding': 'utf-8', 'confidence': 0.7525, 'language': ''}\n" \
          ">>> b_2 = \"是\".encode(\"gbk\") + \"鸽子\".encode(\"utf-8\")\n" \
          ">>> b_2\n" \
          "b'\\xca\\xc7\\xe9\\xb8\\xbd\\xe5\\xad\\x90'\n" \
          "\n" \
          ">>> b_2.decode(\"utf-8\", errors = 'ignore')\n" \
          "'鸽子'\n" \
          ">>> b_2.decode(\"utf-8\", errors = 'replace')\n" \
          "'��鸽子'\n" \
          "\n" \
          ">>> a = \"g\"" \
          ">>> id(a)\n" \
          "25860512\n" \
          ">>> a = a + \"z\"\n" \
          ">>> id(a)\n" \
          "19123520\n" \
          ">>> a\n" \
          "'gz'\n" \
          "\n" \
          ">>> a = \"a\"\n" \
          ">>> a += \"b\"\n" \
          ">>> a\n" \
          "'ab'\n" \
          "\n" \
          ">>> a = \"hello,world\"\n" \
          ">>> a[4]\n" \
          "'o'\n" \
          ">>> a.find(\"o\")\n" \
          "4\n" \
          ">>> f = \"2020-11-22XXXX\"\n" \
          ">>> f.startswith(\"2020-11-22\")\n" \
          "True\n" \
          ">>> f = \"xxxxxxx.jpg\"\n" \
          ">>> f.endswith(\".jpg\")\n" \
          "True\n" \
          "\n" \
          ">>> a = \"faae pigeon, faae pigeon\"\n" \
          ">>> a.replace(\"aae\" , \"ake\")\n" \
          "'fake pigeon, fake pigeon'\n" \
          ">>> a = \"<<python>>,<<java>>,<<c++>>\"\n" \
          ">>> a.split(\",\")\n" \
          "['<<python>>', '<<java>>', '<<c++>>']\n" \
          ">>> b = a.split(\",\")\n" \
          ">>> b\n" \
          "['<<python>>', '<<java>>', '<<c++>>']\n" \
          ">>> \",\".join(b)\n" \
          "'<<python>>,<<java>>,<<c++>>'\n" \
          ">>> a = \"            fake pigeon         \"\n" \
          ">>> a\n" \
          "'            fake pigeon         '\n" \
          ">>> a.strip()\n" \
          "'fake pigeon'\n" \
          ">>> a.lstrip()\n" \
          "'fake pigeon         '\n" \
          ">>> a.rstrip()\n" \
          "'            fake pigeon'"
# 正式写入文件
output.write(content)
# 关闭文件句柄
output.close()